package cn.jhc;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/login.do")
public class LoginServlet extends HttpServlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        
        System.out.println(username);
        System.out.println(password);
        boolean isValid = false;
        try {
            isValid = new DaoRu().login(username, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        

        
        if(isValid) {
            req.getSession().setAttribute("logining_user", username);
            resp.sendRedirect("/admin/list.html");

        }else {
            resp.sendRedirect("/login.html?mes=login_fail");
            System.out.println(isValid);
        }
            

        


    }
    
}
